package tp.pr3.commands;

import tp.pr3.Game;
import tp.pr3.Player;
import tp.pr3.Room;
import tp.pr3.commands.exceptions.CommandExecutionException;
import tp.pr3.commands.exceptions.WrongCommandFormatException;

@SuppressWarnings("unused")  public class QuitCommand implements Command{

	private Game _game;
	private Player _friki;
	private Room _habitacion;
	
	public QuitCommand() {
		this._game=null;
		this._friki=null;
		this._habitacion=null;
	}
	@Override
	public void execute() throws CommandExecutionException {

		this._game.requestQuit();
		this.gameOverMessage();
	}

	@Override
	public String getHelp() {
		return "QUIT | SALIR\n";
	}

	@Override
	public Command parse(String cad, Game execContext)
			throws WrongCommandFormatException {
		
		if (cad.lastIndexOf(' ') != -1)
			throw new WrongCommandFormatException();

		else if (cad.equalsIgnoreCase("QUIT")
				|| cad.equalsIgnoreCase("SALIR"))
		{
			this._friki = execContext.getPlayer();
			this._habitacion = execContext.getCurrentRoom();
			this._game=execContext;
			return this;
		}
		throw new WrongCommandFormatException();
	}
	
	private void gameOverMessage()
	{

		System.out.println("GAME OVER");
		System.out.println(" Thank you for playing, goodbye.");
		String salud, score;
		salud = Integer.toString(this._game.getPlayer().getHealth());
		score = Integer.toString(this._game.getPlayer().getPoints());
		System.out.println("HEALTH = " + salud + ", SCORE =" + score);

	}
}
